

/**
 * 
 * @param {*} reducers 一个对象
 */
function combineReducers(reducers){
    // 返回一个合并后的reducer的函数
    return function combination(totalState={},action){
        let nextState = {}
        for (const key in reducers) {
            // 根据每个子reducer他的老的分状态和动作，计算每个reducer的新的分状态
            nextState[key] = reducers[key](totalState[key],action)
        }
        return nextState
    }
}
export default combineReducers


/**
let reducers = {
    counter1:counter1.reducer
    counter2:counter2.reducer
} 
 */
// ============>
/**
let nextState = {
    counter1:{number:0},
    counter2:{number:0}
}
 */